{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 二维柱状图过滤器 - 实现第一个功能，并调试第一个错误\n",
    "编写代码很重要。但是，要加入一个无人驾驶汽车团队，你的很大一部分工作是与现有的**大型**代码库打交道的。在诸如无人驾驶汽车之类的高风险工程项目中，你可能必须首先获得经理和同事的信任，然后才能让你对代码库进行重大更改。\n",
    "\n",
    "对于团队的新进成员来说，典型的一个任务就是通过许多错误获得进步。所以考虑到这一点，这就是在该纳米学位项目中，你将为你的第一个项目所做的事情。\n",
    "\n",
    "这个项目包括以下几个部分：\n",
    "\n",
    "1. **探索代码** - 此时不要担心错误。我们的目标是熟悉这个代码库的组织方式，并弄清楚各部分分别是做什么的。\n",
    "2. **实现一个功能** - 编写出能让机器人正确移动的代码。\n",
    "3. **修正错误** - 执行动作时，一个以前没有出现过的错误就会显示出来。在这里，你需要确定这个错误是什么，并采取措施进行重现，然后找出原因并加以解决。\n",
    "\n",
    "\n",
    "## 第1部分：探索代码\n",
    "在这一部分，你只需运行一些现有代码，即可对定位器的概况有所熟悉。\n",
    "\n",
    "你可以使用键盘上的箭头键浏览此 notebook 。你可以通过按下**`Ctrl + Enter`** 即可在单元格中运行代码。\n",
    "\n",
    "浏览下面的单元格。在每个单元格，你应该：\n",
    "\n",
    "1. 通读代码。如果这时你没有完全理解所有的代码，没关系。\n",
    "2. 猜一猜运行代码时会发生什么。\n",
    "3. 运行代码，并将你所看到的与你的预期进行比较。\n",
    "4. 浏览到**TODO** 部分时，请仔细阅读说明，并完成相关任务。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/iroan/tools/anaconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:278: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.\n",
      "  'Matplotlib is building the font cache using fc-list. '\n"
     ]
    }
   ],
   "source": [
    "# This code \"imports\" code from some of the other files we've written\n",
    "# in this directory. Specifically simulate.py and helpers.py\n",
    "import simulate as sim\n",
    "import helpers\n",
    "import localizer\n",
    "\n",
    "# Don't worry too much about this code for now...\n",
    "from __future__ import division, print_function\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl8VNXdP/DPN8kkk8kkrFF2IosrRYSIqHXfN2gVW1yw1AU3qk+puLX1qdr6PFgVN54qLnVBK1bRBquida1a0LBrQTZBKFuQQAgJCZn5/P44kx8xTDL3Tu7k3rnzfb9e9+VM5tw7Xw/3fu+Zc+85V0hCKaWUv2S5HYBSSinnaXJXSikf0uSulFI+pMldKaV8SJO7Ukr5kCZ3pZTyIU3uSinlQ5rclVLKhzS5K6WUD+W49cVdu3ZlSUmJW1+vlFJpad68eVtJFicq51pyLykpQXl5uVtfr5RSaUlE1lopp90ySinlQ5rclVLKh1zrlkkGCXz6KfDYY8CqVeZv/foBV18NHHccIOJufF6zZg3wf/8HzJkD1NYCXbsCF18MXHghEAy6HZ23VFcD06cDr74KbN8OhMPACScA11wDdOvmdnTeEo0C77wDPPUUsG4dkJ0NHHwwcP31wNChbkfnPf/+NzB1KrBoEVBfD3TvDowbB5x3HpCTygxM0pVl2LBhtOPtt8mSErKggBQhTao3r8Nhsm9f8s03bW3St9auJU86iQwGydzcvXUFmLoKh8n//m8yEnE7UvfV1ZETJpD5+WbfalpXwSCZl0eOHElWVLgdqTdMn07uv7/Zh5rWVVYWGQqRhx5K/utfbkfpDUuWkMOGmX0rJ+f79VVYSHbuTD76KBm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K6UUj70/wAWr/PHYBiP2AAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# This code defines a 5x5 robot world as well as some other parameters\n",
    "# which we will discuss later. It then creates a simulation and shows \n",
    "# the initial beliefs. \n",
    "R = 'r'\n",
    "G = 'g'\n",
    "grid = [\n",
    "    [R,G,G,G,R],\n",
    "    [G,G,R,G,R],\n",
    "    [G,R,G,G,G],\n",
    "    [R,R,G,R,G],\n",
    "    [R,G,R,G,R],\n",
    "]\n",
    "blur = 0.05\n",
    "p_hit = 200.0\n",
    "simulation = sim.Simulation(grid, blur, p_hit)\n",
    "simulation.show_beliefs()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "重复按下Ctrl + Enter，多次运行该代码。\n",
    "\n",
    "每次运行后，观察状态是如何改变的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "list indices must be integers or slices, not float",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-3-6e2a55cfcdd5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msimulation\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0msimulation\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow_beliefs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/workspace/project/owner/politless/python_histogram_filter/simulate.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, num_steps)\u001b[0m\n\u001b[1;32m    121\u001b[0m         '''\n\u001b[1;32m    122\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnum_steps\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 123\u001b[0;31m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msense\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    124\u001b[0m             \u001b[0mdy\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom_move\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    125\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmove\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdy\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/workspace/project/owner/politless/python_histogram_filter/simulate.py\u001b[0m in \u001b[0;36msense\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     50\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     51\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0msense\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 52\u001b[0;31m         \u001b[0mcolor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_observed_color\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     53\u001b[0m         \u001b[0mbeliefs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdeepcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbeliefs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     54\u001b[0m         \u001b[0mnew_beliefs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlocalizer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msense\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcolor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgrid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbeliefs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mp_hit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mp_miss\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/workspace/project/owner/politless/python_histogram_filter/simulate.py\u001b[0m in \u001b[0;36mget_observed_color\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     70\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mget_observed_color\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     71\u001b[0m         \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrue_pose\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 72\u001b[0;31m         \u001b[0mtrue_color\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgrid\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     73\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mincorrect_sense_probability\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     74\u001b[0m             \u001b[0mpossible_colors\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: list indices must be integers or slices, not float"
     ]
    }
   ],
   "source": [
    "simulation.run(1)\n",
    "simulation.show_beliefs()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "你认为调用`run` 是用来做什么的？看一看**`simulate.py`**中的代码，并找出答案。\n",
    "\n",
    "花几分钟看一看`run`方法及其调用的方法，熟悉一下具体是如何工作的。\n",
    "\n",
    "#### 我在看什么？\n",
    "\n",
    "红色星星表示机器人的真实位置。蓝色圆圈表示机器人认为它处于任何一个特定位置的信念强度。\n",
    "\n",
    "理想情况下，我们希望最大的蓝色圆圈与红色星星处于相同的位置。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We will provide you with the function below to help you look\n",
    "# at the raw numbers.\n",
    "\n",
    "def show_rounded_beliefs(beliefs):\n",
    "    for row in beliefs:\n",
    "        for belief in row:\n",
    "            print(\"{:0.3f}\".format(belief), end=\"  \")\n",
    "        print()\n",
    "        \n",
    "# The {:0.3f} notation is an example of \"string \n",
    "# formatting\" in Python. You can learn more about string \n",
    "# formatting at https://pyformat.info/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "show_rounded_beliefs(simulation.beliefs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "_____\n",
    "\n",
    "## 第2部分：实现2D感测函数\n",
    "正如你所看到的，机器人的判断并没有改变。无论我们调用多少次这个模拟的感测方法，机器人的判断都没有发生变化，它的判断是一致的。\n",
    "\n",
    "### 说明\n",
    "1. 打开`localizer.py`并完成`sense`函数。\n",
    "2. 运行下面单元格中的代码，导入定位器模块（或重新加载它），然后测试你的感测函数。\n",
    "3. 如果测试通过，表明你已经成功实现了第一个功能！继续进行这个项目吧。如果测试没有通过（可能不会出现在测试的前几次），继续修改你的`sense`函数，直到通过测试！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tests pass! Your sense function is working as expected\n"
     ]
    }
   ],
   "source": [
    "reload(localizer)\n",
    "def test_sense():\n",
    "    R = 'r'\n",
    "    _ = 'g'\n",
    "\n",
    "    simple_grid = [\n",
    "        [_,_,_],\n",
    "        [_,R,_],\n",
    "        [_,_,_]\n",
    "    ]\n",
    "\n",
    "    p = 1.0 / 9\n",
    "    initial_beliefs = [\n",
    "        [p,p,p],\n",
    "        [p,p,p],\n",
    "        [p,p,p]\n",
    "    ]\n",
    "\n",
    "    observation = R\n",
    "\n",
    "    expected_beliefs_after = [\n",
    "        [1/11, 1/11, 1/11],\n",
    "        [1/11, 3/11, 1/11],\n",
    "        [1/11, 1/11, 1/11]\n",
    "    ]\n",
    "\n",
    "    p_hit  = 3.0\n",
    "    p_miss = 1.0\n",
    "    beliefs_after_sensing = localizer.sense(\n",
    "        observation, simple_grid, initial_beliefs, p_hit, p_miss)\n",
    "\n",
    "    if helpers.close_enough(beliefs_after_sensing, expected_beliefs_after):\n",
    "        print(\"Tests pass! Your sense function is working as expected\")\n",
    "        return\n",
    "    \n",
    "    elif not isinstance(beliefs_after_sensing, list):\n",
    "        print(\"Your sense function doesn't return a list!\")\n",
    "        return\n",
    "        \n",
    "    elif len(beliefs_after_sensing) != len(expected_beliefs_after):\n",
    "        print(\"Dimensionality error! Incorrect height\")\n",
    "        return\n",
    "              \n",
    "    elif len(beliefs_after_sensing[0] ) != len(expected_beliefs_after[0]):\n",
    "        print(\"Dimensionality Error! Incorrect width\")\n",
    "        return\n",
    "    \n",
    "    elif beliefs_after_sensing == initial_beliefs:\n",
    "        print(\"Your code returns the initial beliefs.\")\n",
    "        return\n",
    "        \n",
    "    total_probability = 0.0\n",
    "    for row in beliefs_after_sensing:\n",
    "        for p in row:\n",
    "            total_probability += p\n",
    "    if abs(total_probability-1.0) > 0.001:\n",
    "        \n",
    "        print(\"Your beliefs appear to not be normalized\")\n",
    "        return\n",
    "    \n",
    "    print(\"Something isn't quite right with your sense function\")\n",
    "\n",
    "test_sense()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 集成测试\n",
    "在我们称之为“完整”之前，应该执行一次**集成测试**。虽然我们已经验证了感测函数可以独立使用，但这个定位器是否可以正常工作呢？\n",
    "\n",
    "我们来执行一个集成测试。首先，在下面的单元格中执行代码用于准备仿真环境。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from simulate import Simulation\n",
    "import simulate as sim\n",
    "import helpers\n",
    "reload(localizer)\n",
    "reload(sim)\n",
    "reload(helpers)\n",
    "\n",
    "R = 'r'\n",
    "G = 'g'\n",
    "grid = [\n",
    "    [R,G,G,G,R,R,R],\n",
    "    [G,G,R,G,R,G,R],\n",
    "    [G,R,G,G,G,G,R],\n",
    "    [R,R,G,R,G,G,G],\n",
    "    [R,G,R,G,R,R,R],\n",
    "    [G,R,R,R,G,R,G],\n",
    "    [R,R,R,G,R,G,G],\n",
    "]\n",
    "\n",
    "# Use small value for blur. This parameter is used to represent\n",
    "# the uncertainty in MOTION, not in sensing. We want this test\n",
    "# to focus on sensing functionality\n",
    "blur = 0.1\n",
    "p_hit = 100.0\n",
    "simulation = sim.Simulation(grid, blur, p_hit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3XeYFeXd//H3vX3PskuREhQUsRcUZS2IDdFgISbGGsuj0YgaY0miRpPLRxM1muhjyZOi2I390RiJFTEWrLgEiA3RHyBVdhEEtrHt+/vjXkLb3TOnzpnl87quuXb37OzMd/ac+cw99zRnZoiISHTkhV2AiIgkRsEtIhIxCm4RkYhRcIuIRIyCW0QkYhTcIiIRo+AWEYkYBbeISMQouEVEIqYgExPt27evDRkyJBOTFhHplqZNm7bMzPoFGTcjwT1kyBCqqqoyMWkRkW7JOfdl0HHVVSIiEjEKbhGRiFFwi4hEjIJbRCRiFNwiIhETKLidc72cc08552Y55z51zo3MdGFrtbXBK6/AbbfBm29CVJ/7sGIFTJoE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+AWEYkYBbeISMQouEVEIkbBLSISMQpuEZGIUXCLiESMgltEJGL+Px4PwGEjhKzDAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc5ed831510>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Use control+Enter to run this cell many times and observe how \n",
    "# the robot's belief that it is in each cell (represented by the\n",
    "# size of the corresponding circle) changes as the robot moves.\n",
    "# The true position of the robot is given by the red star.\n",
    "\n",
    "# Run this cell about 15-25 times and observe the results\n",
    "for i in range(10):\n",
    "    simulation.run(1)\n",
    "simulation.show_beliefs()\n",
    "\n",
    "# If everything is working correctly you should see the beliefs\n",
    "# converge to a single large circle at the same position as the \n",
    "# red star.\n",
    "#\n",
    "# When you are satisfied that everything is working, continue\n",
    "# to the next section"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第3部分：识别并重现错误\n",
    "软件出现了错误，没关系。\n",
    "\n",
    "你的机器人用户会把这种错误称为技术支持与投诉，比如：\n",
    "\n",
    "> “我在一个方形的房间里使用你的机器人时，一切都很好，然后我试着在一个矩形房间里加载了一个地图，之后机器人行驶了几秒钟，突然就停止工作了。请修复一下吧！“\n",
    "\n",
    "现在，必须要进行调试。我们将采用系统化的方法试一试。\n",
    "\n",
    "1. 重现这个错误。\n",
    "2. 阅读（并理解）错误消息（当存在时）。\n",
    "3. 编写一个触发这个错误的测试。\n",
    "4. 生成一个错误成因的假设。\n",
    "5. 尝试解决它。如果修复了这个错误，太棒了！如果没有修复，请返回步骤4。\n",
    "\n",
    "### 第1步：重现错误\n",
    "根据用户的描述，**矩形环境**似乎是造成这个错误的原因。\n",
    "\n",
    "下面的代码与你在对新功能进行集成测试时使用的代码相同。看一看是否可以通过修改它来重现错误。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAY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MTW99nd5nnio9zThtxUO72fbsxsLPBFYFboWiRhZsOAw0juf4G7t1cr2KH2wj3NzbolIDObABwAvBS2ktLkhjIWAKuAee5ek9sB/AK4FOgKXUgFOPCEmTXn7sNcq/4FaAHuyA2XzTKzIdVaWa2Fe6obcUsYZrYD8ABwkbu3hq6nFO7e6e77A2OBSWZWc0NmZnY8sMrdm0PXUiFT3f1A4Djg/NyQZi2qBw4EbnH3A4D1QNW+N6y1cF8GjOv2fCywPFAt0k1ujPoB4Lfu/vvQ9ZQr99/lZ4BjA5dSiqnAjNxY9b3AEWZ2d9iSSufuy3M/VwEPkgzP1qJlwLJu/xu8nyTsq6LWwj3Nzbqln+W+iLwdWOTu14Wup1RmNtLMdso9HgwcBbwRtqriufvl7j7W3SeQ/I085e6nBS6rJGY2JPclPbkhjGOAmjzCzN3fA5aa2d65l44EqnbQQap7qG4rertZd+CySmJm9wDTgBFmtgy4wt1vD1tVyaYCpwOv5carAb6bu/duLRkNzMkdlTUA+J271/RhhBHYDXgw6T9QD/yPu/8xbEll+Sbw21zn9B/AWdVaUU0dCikiIunU2rCMiIikoHAXEYmQwl1EJEIKdxGRCCncRUQipHAXEYmQwl1EJEIKdxGRCP0/UY4/fZ7Jp2AAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc5ed814890>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from simulate import Simulation\n",
    "import simulate as sim\n",
    "import helpers\n",
    "reload(localizer)\n",
    "reload(sim)\n",
    "reload(helpers)\n",
    "\n",
    "R = 'r'\n",
    "G = 'g'\n",
    "\n",
    "grid = [ \n",
    "    [R,G,G,G,R,R,R],\n",
    "    [G,G,R,G,R,G,R],\n",
    "    [G,R,G,G,G,G,R],\n",
    "    [R,R,G,R,G,G,G],\n",
    "]\n",
    "\n",
    "blur = 0.001\n",
    "p_hit = 100.0\n",
    "simulation = sim.Simulation(grid, blur, p_hit)\n",
    "\n",
    "# remember, the user said that the robot would sometimes drive around for a bit...\n",
    "# It may take several calls to \"simulation.run\" to actually trigger the bug.\n",
    "for i in range(10):\n",
    "    simulation.run(1)\n",
    "simulation.show_beliefs()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "simulation.run(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 第2步：阅读并理解错误消息\n",
    "如果你触发了这个错误，就应该在这个单元格的正上方看到一条错误消息。该消息的结尾应该是这样的："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "IndexError: list index out of range"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "而在这条消息的正上面，你应该看到了类似这样的代码："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "path/to/your/directory/localizer.pyc in move(dy, dx, beliefs, blurring)\n",
    "     38             new_i = (i + dy ) % width\n",
    "     39             new_j = (j + dx ) % height\n",
    "---> 40             new_G[int(new_i)][int(new_j)] = cell\n",
    "     41     return blur(new_G, blurring)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这些代码表示，移动函数中的第40行导致出现了`IndexError`，因为“列表索引超出范围”。\n",
    "\n",
    "如果你不确定这表示什么含义，请使用Google！\n",
    "\n",
    "把`IndexError: list index out of range`复制粘贴在Google的搜索框！当我这样做时，我看到了下面的搜索结果：\n",
    "\n",
    "![Search Results](http://i.imgur.com/gleBmBy.png)\n",
    "\n",
    "浏览最上面的几个链接（通常这些都来自堆栈溢出），并阅读人们对这种错误的评论，直到你找到满意答案，了解该错误是如何产生的。\n",
    "\n",
    "### 第3步：编写一个重现错误的测试\n",
    "这样做可以帮助你了解何时修复它，并确保未来不会再出现这种错误。 你可能需要尝试许多潜在的解决方案，所以最好的情况是，只需调用一个函数即可确认该错误是否已修复。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# According to the user, sometimes the robot actually does run \"for a while\" \n",
    "# - How can you change the code so the robot runs \"for a while\"?\n",
    "# - How many times do you need to call simulation.run() to consistently\n",
    "#   reproduce the bug?\n",
    "# Modify the code below so that when the function is called \n",
    "# it consistently reproduces the bug.\n",
    "def test_robot_works_in_rectangle_world():\n",
    "    from simulate import Simulation\n",
    "    import simulate as sim\n",
    "    import helpers\n",
    "    reload(localizer)\n",
    "    reload(sim)\n",
    "    reload(helpers)\n",
    "\n",
    "    R = 'r'\n",
    "    G = 'g'\n",
    "\n",
    "    grid = [ \n",
    "        [R,G,G,G,R,R,R],\n",
    "        [G,G,R,G,R,G,R],\n",
    "        [G,R,G,G,G,G,R],\n",
    "        [R,R,G,R,G,G,G],\n",
    "    ]\n",
    "\n",
    "    blur = 0.001\n",
    "    p_hit = 100.0\n",
    "    for i in range(1000):\n",
    "        simulation = sim.Simulation(grid, blur, p_hit)\n",
    "        simulation.run(1)\n",
    "    \n",
    "test_robot_works_in_rectangle_world()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 第4步：生成一个假设\n",
    "为了猜测错误出现的原因，使用一些Python调试工具会很有帮助。\n",
    "\n",
    " `pdb`模块（`p`ython `d`e`b`ugger）在这里会很有帮助！\n",
    "\n",
    "#### 设置调试器 \n",
    "1. 打开`localizer.py`并取消import pdb`的顶部的行的批注。\n",
    "2. 在导致出现错误`new_G[int(new_i)][int(new_j)] = cell`的代码行之前，添加一行新的代码`pdb.set_trace()` 。\n",
    "3. 通过调用你的测试函数运行这个测试（运行下面的单元格）。\n",
    "4. 你应该看到弹出了一个文本输入框！现在，在这个输入框中键入`c`并按回车键**继**续程序的执行。继续输入`c`并按回车键，直到再次触发这个错误。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_robot_works_in_rectangle_world()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 使用调试器\n",
    "调试器通过在代码中编写`pdb.set_trace()`的任何地方暂停程序执行来正常工作。你也可以访问你的代码中可以访问的任意变量。\n",
    "\n",
    "尝试再次运行你的测试。这一次，当文本输入框出现时，输入`new_i`并按回车键。你会在调试器窗口中看到`new_i`变量的值。多运行几次调试器：找到`new_j` 、`height` 与`new_i`的值。它们看起来是否合理或正确？\n",
    "\n",
    "之后，输入`c` ，继续执行程序。是否再次触发了那个错误？继续尝试，直到猜测到导致出现错误的原因。\n",
    "\n",
    "### 第5步：编写一个修复程序\n",
    "你有一个关于出现这个错误的假设。现在尝试修复它。完成后，再次调用你的测试函数。你可能希望删除（或标注出）添加到`localizer.py`中的行，即`pdb.set_trace()`。这样你的测试就可以运行了，而无需在调试器框中键入`c`。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_robot_works_in_rectangle_world()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 恭喜你！\n",
    "恭喜你！你已经实现了你的第一个功能，并成功调试了机器人在矩形环境中遇到的错误。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
